

package com.cisdi.info.simple.controller.organization;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;
import com.cisdi.info.simple.dto.base.PageDTO;
import com.cisdi.info.simple.dto.base.PageResultDTO;
import com.cisdi.info.simple.service.system.CodeTableService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.cisdi.info.simple.dto.organization.TestEmployeeEditDto;
import com.cisdi.info.simple.entity.organization.TestEmployee;
import com.cisdi.info.simple.service.organization.TestEmployeeService;
import com.cisdi.info.simple.service.organization.OrganizationService;



/**module
{
"simple/organization/TestEmployee": {
"code": "simple/organization/TestEmployee",
"name1": "测试表单",
"url": "/simple/organization/TestEmployee",
"route": "/simple/organization/TestEmployee",
"iconClass": "",
"displayIndex": 1,
"parentCode": "simple/organization",
"parentName": "组织机构",
"moduleType": "电脑模块",
"isInUse": "是",
"routeParamsObj": "",
"permissions":
	[
	{
	"code": "simple_organization_TestEmployee_Add",
	"name1": "新增",
	"fullName": "simple.组织机构.测试表单.新增",
	"moduleCode": "simple/organization/TestEmployee",
	urls:[
		"/simple/organization/TestEmployee/createTestEmployee",
		"/simple/organization/TestEmployee/saveTestEmployee"
			
		,"/simple/organization/Organization/findOrganizationsWithIdNameByName"
	]
	},
	{
	"code": "simple_organization_TestEmployee_Edit",
	"name1": "编辑",
	"fullName": "simple.组织机构.测试表单.编辑",
	"moduleCode": "simple/organization/TestEmployee",
	urls:[
		"/simple/organization/TestEmployee/findTestEmployeeForEdit",
		"/simple/organization/TestEmployee/updateTestEmployee"
		
		,"/simple/organization/Organization/findOrganizationsWithIdNameByName"
	]
	},
	{
	"code": "simple_organization_TestEmployee_Delete",
	"name1": "删除",
	"fullName": "simple.组织机构.测试表单.删除",
	"moduleCode": "simple/organization/TestEmployee",
	urls:[
	"/simple/organization/TestEmployee/deleteTestEmployee"
	]
	},
	{
	"code": "simple_organization_TestEmployee_View",
	"name1": "查看",
	"fullName": "simple.组织机构.测试表单.查看",
	"moduleCode": "simple/organization/TestEmployee",
	urls:[
	"/simple/organization/TestEmployee/findTestEmployees",
	"/simple/organization/TestEmployee/findTestEmployeeForView"
	]
	}
	]
}
}
*/

@RestController
@RequestMapping("/simple/organization/TestEmployee")
@CrossOrigin(allowCredentials = "true")
public class TestEmployeeController {
	private static Logger logger = LogManager.getLogger();



			
			
	@Autowired private TestEmployeeService testEmployeeService;
	@Autowired private CodeTableService codeTableService;
	@Autowired private OrganizationService organizationService;

	@PostMapping("/findTestEmployees")
	public PageResultDTO findTestEmployees(@RequestBody PageDTO pageDTO){
		return this.testEmployeeService.findTestEmployees(pageDTO);
	}

	@GetMapping("/findTestEmployee")
	public TestEmployee findTestEmployee(@RequestParam Long testEmployeeId)
	{
		return this.testEmployeeService.findTestEmployee(testEmployeeId);
	}

	@GetMapping("/findTestEmployeeForView")
	public TestEmployee findTestEmployeeForView(@RequestParam Long testEmployeeId)
	{
		return this.testEmployeeService.findTestEmployeeWithForeignName(testEmployeeId);
	}

	@GetMapping("/findTestEmployeeForEdit")
	public TestEmployeeEditDto findTestEmployeeForEdit(@RequestParam Long testEmployeeId)
	{
		TestEmployeeEditDto testEmployeeEditDto = new TestEmployeeEditDto();
		testEmployeeEditDto.setTestEmployee(this.testEmployeeService.findTestEmployeeWithForeignName(testEmployeeId));

		this.prepareTestEmployeeEditDto(testEmployeeEditDto);

		return testEmployeeEditDto;
	}

	//创建新的测试表单
	@GetMapping("/createTestEmployee")
	public TestEmployeeEditDto createTestEmployee()
	{
		TestEmployeeEditDto testEmployeeEditDto = new TestEmployeeEditDto();
		testEmployeeEditDto.setTestEmployee(new TestEmployee());

		this.prepareTestEmployeeEditDto(testEmployeeEditDto);
		return testEmployeeEditDto;
	}

	private void prepareTestEmployeeEditDto(TestEmployeeEditDto testEmployeeEditDto)
	{
		testEmployeeEditDto.setGenderCodeTables(this.codeTableService.findCodeTablesByCodeType("Gender"));
        //TODO: 以下代码可以注释掉，此行代码即时加载所有外键对象，以便选择。如果不在此加载，可以在界面上实现延迟加载。如果外键对象超过 500 行，建议采用延迟加载
		testEmployeeEditDto.setOrganizationOrganizations(this.organizationService.findAllOrganizationsWithIdName());
	}

	@PostMapping("/saveTestEmployee")
	public TestEmployee saveTestEmployee(@RequestBody TestEmployee testEmployee)
	{
		return this.testEmployeeService.saveTestEmployee(testEmployee);
	}

	@PostMapping("/updateTestEmployee")
	public TestEmployee updateTestEmployee(@RequestBody TestEmployee testEmployee)
	{
		return this.testEmployeeService.updateTestEmployee(testEmployee);
	}

	@GetMapping("/deleteTestEmployee")
	public void deleteTestEmployee(@RequestParam Long testEmployeeId)
	{
		this.testEmployeeService.deleteTestEmployee(testEmployeeId);
	}
	@GetMapping("/findTestEmployeesWithIdNameById")
	public TestEmployee findTestEmployeesWithIdNameById(@RequestParam Long testEmployeeId)
	{
		return this.testEmployeeService.findTestEmployeesWithIdNameById(testEmployeeId);
	}

	@GetMapping("/findTestEmployeesWithIdNameByName")
	public List<TestEmployee> findTestEmployeesWithIdNameByName(String testEmployeeName)
	{
		return this.testEmployeeService.findTestEmployeesWithIdNameByName(testEmployeeName);
	}
}

